package com.zbkj.admin.controller.platform;

import com.github.pagehelper.PageInfo;
import com.zbkj.dal.base.page.CommonPage;
import com.zbkj.dal.pojo.request.PageParamRequest;
import com.zbkj.dal.pojo.request.ba.ConfirmRequest;

import com.zbkj.dal.pojo.request.ba.QueryBookingRequest;
import com.zbkj.dal.pojo.response.ba.BookingResponse;
import com.zbkj.dal.base.result.CommonResult;
import com.zbkj.service.service.BookingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@RequestMapping("api/admin/platform/booking")
@Api(tags = "卡座预约")
public class BookingController {
    @Autowired
    private BookingService bookingService;

    @ApiOperation(value = "分页获取卡座预约信息")
    @RequestMapping(value = "/pageBookings", method = RequestMethod.POST)
    public CommonResult<CommonPage<BookingResponse>> queryBookings(@RequestBody QueryBookingRequest queryBookingRequest, PageParamRequest pageParamRequest) {
        if (CollectionUtils.isNotEmpty(queryBookingRequest.getTimes())) {
            queryBookingRequest.setBeginDate(queryBookingRequest.getTimes().get(0));
            queryBookingRequest.setEndDate(queryBookingRequest.getTimes().get(1));
        }
        PageInfo<BookingResponse> sharePageInfo = bookingService.queryBookings(queryBookingRequest, pageParamRequest);
        return CommonResult.success(CommonPage.restPage(sharePageInfo));
    }

    @ApiOperation(value = "卡座预约详情")
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    public CommonResult<BookingResponse> detail(@PathVariable("id")Integer id) {
        return CommonResult.success(bookingService.detail(id));
    }

    @ApiOperation(value = "确认卡座预约信息")
    @RequestMapping(value = "/confirm", method = RequestMethod.POST)
    public CommonResult<Boolean> confirm(@Validated @RequestBody ConfirmRequest confirmRequest) {
        return CommonResult.success(bookingService.confirm(confirmRequest));
    }
}
